package com.tz.pay.weixin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tz.pay.PayBean;
import com.tz.pay.PayParamUtil;
import com.tz.pay.marlon.core.service.PaymentAct;

/**
 * 
 * TzWeiXinPayController<BR>
 * 作者:Marlon  <BR>
 * 时间:2016年10月29日-下午3:02:29 <BR>
 * 邮箱:18093454447@163.com  <BR>
 * @version 1.0.0  <BR>
 * @link see:  <BR>
 */
@Controller
@RequestMapping("/weixin")
public class TzWeiXinPayController {

	@ResponseBody
	@RequestMapping(value="/pay",method=RequestMethod.POST)
	public String index(PayBean payBean,HttpServletRequest request,HttpServletResponse response) {
		String result = PaymentAct.goWeixinPay(payBean,request,response);
//		String result = PayParamUtil.goWeixinPay(payBean);
//		request.getSession().setAttribute("product_id", payBean.getPno());
		request.getSession().setAttribute("imgurl", result);
//		System.out.println("################" + result);
		return result;
	}
	
	@RequestMapping(value="/paying")
	public String paying(String money,HttpServletRequest request,HttpServletResponse response){
		String imgurl = (String) request.getSession().getAttribute("imgurl");
		request.setAttribute("imgurl", imgurl);
		request.setAttribute("money", money);
		System.out.println(imgurl);
		return "forward:/pages/wxfk.jsp";
	}
	
	@RequestMapping(value="/payed",method=RequestMethod.POST)
	public String pay(HttpServletRequest request) {
		String productId = (String) request.getSession().getAttribute("product_id");
		String result = PaymentAct.queryOrder(productId);
		return result;
	}
}